use crate::controller::Error;
use crate::dto;
use crate::service::ServiceSet;
use std::sync::Arc;

pub struct AuthController {
    service_set: Arc<ServiceSet>,
}

impl AuthController {
    pub fn new(service_set: Arc<ServiceSet>) -> Self {
        Self { service_set }
    }

    pub async fn login_apply(
        &self,
        request: &dto::auth::LoginApplyRequest,
    ) -> Result<dto::auth::LoginResponseData, Error> {
        let data = self.service_set.auth.login_apply(request).await?;
        Ok(data)
    }

    pub async fn login_submit(
        &self,
        request: &dto::auth::LoginSubmitRequest,
    ) -> Result<dto::auth::Token, Error> {
        let data = self.service_set.auth.login_submit(request).await?;
        Ok(data)
    }

    pub async fn refresh_token(
        &self,
        request: &dto::auth::RefreshTokenRequest,
    ) -> Result<dto::auth::Token, Error> {
        let data = self.service_set.auth.refresh_token(request).await?;
        Ok(data)
    }

    pub async fn get_auth_info(&self, access_token: &str) -> Result<dto::auth::AuthInfo, Error> {
        let data = self.service_set.auth.get_auth_info(access_token).await?;
        Ok(data)
    }
}
